/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nokia.iap.ui.lib.onebutton;

import com.nokia.mid.payment.IAPClientPaymentManager;


/**
 *
 * @author zinin
 */
public class GxButtonBuy extends GxButtonBase{
    private final OneButtonIAP context;
    private boolean isInprogress;
    
    public GxButtonBuy(OneButtonIAP client, GxColorTheme theme){
        super("Buy", 0, 0, theme);
        context = client;
    }

    public void performAction() {
        context.screenBuf.delete(0, context.screenBuf.length());
        context.screenBuf.append(context.KHorzCenterMark + "..please wait..");
        int errcode = context.iapClient.purchaseProduct(OneButtonIAP.productID, IAPClientPaymentManager.FORCED_AUTOMATIC_RESTORATION);
        if(errcode == IAPClientPaymentManager.SUCCESS){
            this.setVisible(false);
        }else{
            context.screenBuf.delete(0, context.screenBuf.length());
            context.screenBuf.append(context.KHorzCenterMark + "ERROR : ").append(String.valueOf(errcode)).append("\n");
            isInprogress = false;
        }
    }

    public boolean isHidden() {
        return (!isVisible());
    }
}
